/*
 * CcLinkage.c
 *
 *  Created on: 2012/04/27
 *      Author: guanxiaoying
 */

#include "../coredef.h"
static BOOL linkageCheckLinkType( AST astType, AST astNewType );
static BOOL linkageCheckBasicLinkType( AST astType, AST astNewType ){
	return astType == astNewType;
}
static BOOL linkageCheckArrayLinkType( AST astType, AST astNewType ){
	BOOL bRet;
	AST astOrgType;
	AST astNewOrgType;

	if( astType == astNewType ){
		return TRUE;
	}

	astOrgType = stLinkTypeInfoAccess.elementType.get( astType );
	astNewOrgType = stLinkTypeInfoAccess.elementType.get( astNewType );
	bRet = linkageCheckLinkType( astOrgType, astNewOrgType );
	if( bRet == FALSE ){
		return FALSE;
	}
	if( stLinkTypeInfoAccess.typeQual.get( astType )
			!= stLinkTypeInfoAccess.typeQual.get( astNewType )){
		return FALSE;
	}
	if( stLinkTypeInfoAccess.bSizeUnDefined.get( astType )
		|| stLinkTypeInfoAccess.bSizeUnDefined.get( astNewType )){
		return TRUE;
	}
	if( stLinkTypeInfoAccess.bVariableSize.get( astType )
		&& stLinkTypeInfoAccess.bVariableSize.get( astNewType )){
		return TRUE;
	}
	if( stLinkTypeInfoAccess.bVariableSize.get( astType )
		|| stLinkTypeInfoAccess.bVariableSize.get( astNewType )){
		return FALSE;
	}
	if( stLinkTypeInfoAccess.size.get( astType ) != 0
		&& stLinkTypeInfoAccess.size.get( astNewType ) != 0
		&& stLinkTypeInfoAccess.size.get( astType )
		!= stLinkTypeInfoAccess.size.get( astNewType ) ){
		return FALSE;
	}
	return TRUE;
}
static BOOL linkageCheckPointerLinkType( AST astType, AST astNewType ){
	BOOL bRet;
	AST astOrgType;
	AST astNewOrgType;

	if( astType == astNewType ){
		return TRUE;
	}
	astOrgType = stLinkTypeInfoAccess.elementType.get( astType );
	astNewOrgType = stLinkTypeInfoAccess.elementType.get( astNewType );
	bRet = linkageCheckLinkType( astOrgType, astNewOrgType );
	if( bRet == FALSE ){
		return FALSE;
	}
	if( stLinkTypeInfoAccess.typeQual.get( astType )
			!= stLinkTypeInfoAccess.typeQual.get( astNewType )){
		return FALSE;
	}
	return TRUE;
}
static BOOL linkageCheckStructLinkType( AST astType, AST astNewType ){
	BOOL bRet;
	AST memChain;
	AST memNewChain;
	AST astMemType;
	AST astNewMemType;
	PSZ memName1;
	PSZ memName2;

	if( astType == astNewType ){
		return TRUE;
	}
	memName1 = stLinkTypeInfoAccess.tagName.get( astType );
	memName2 = stLinkTypeInfoAccess.tagName.get( astNewType );
	if( memName1 != NULL && memName1[0] != '\0'){
		if( memName2 != NULL && memName2[0] != '\0'){
			if( strcmp( memName1, memName2 )){
				return FALSE;
			}
		}
	}
	memChain = stLinkTypeInfoAccess.memChain.get( astType );
	memNewChain = stLinkTypeInfoAccess.memChain.get( astNewType );
	while( memChain ){
		if( memNewChain == 0 ){
			break;
		}
		astMemType = stMemberSymbolAccess.type.get( memChain );
		astNewMemType = stMemberSymbolAccess.type.get( memNewChain );

		memName1 = stMemberSymbolAccess.name.get( memChain );
		memName2 = stMemberSymbolAccess.name.get( memNewChain );
		if( memName1 == NULL || memName1[0] == '\0'){
			if( memName2 != NULL && memName2[0] != '\0'){
				return FALSE;
			}
		}else{
			if( memName2 == NULL || memName2[0] == '\0'){
				return FALSE;
			}
			if( strcmp( memName1, memName2 )){
				return FALSE;
			}
		}
		bRet = linkageCheckLinkType( astMemType, astNewMemType );
		if( bRet == FALSE ){
			return FALSE;
		}
		memChain = stMemberSymbolAccess.next.get( memChain );
		memNewChain = stMemberSymbolAccess.next.get( memNewChain );
	}
	if( memChain != 0 || memNewChain != 0 ){
		return FALSE;
	}
	return TRUE;
}

static BOOL linkageCheckUnionLinkType( AST astType, AST astNewType ){
	BOOL bRet;
	/*debug,13/1/10,S*/
	AST memChain;
	AST memNewChain;
	/*debug,13/1/10,E*/
	U4  memNumber1=0;
	U4  memNumber2=0;
	AST astMemType;
	AST astNewMemType;
	PSZ memName1;
	PSZ memName2;

	if( astType == astNewType ){
		return TRUE;
	}
	memName1 = stLinkTypeInfoAccess.tagName.get( astType );
	memName2 = stLinkTypeInfoAccess.tagName.get( astNewType );
	if( memName1 != NULL && memName1[0] != '\0'){
		if( memName2 != NULL && memName2[0] != '\0'){
			if( strcmp( memName1, memName2 )){
				return FALSE;
			}
		}
	}

	memChain = stLinkTypeInfoAccess.memChain.get( astType );
	memNewChain = stLinkTypeInfoAccess.memChain.get( astNewType );
	while( memChain ){
		memName1 = stMemberSymbolAccess.name.get( memChain );
		if( memName1 != NULL && memName1[0] != '\0'){
			memNumber1++;
		}
		memChain = stMemberSymbolAccess.next.get( memChain );
	}
	while( memNewChain ){
		memName2 = stMemberSymbolAccess.name.get( memNewChain );
		if( memName2 != NULL && memName2[0] != '\0'){
			memNumber2++;
		}
		memNewChain = stMemberSymbolAccess.next.get( memNewChain );
	}
	if( memNumber1 != memNumber2 ){
		return FALSE;
	}
	memChain = stLinkTypeInfoAccess.memChain.get( astType );
	while(memChain){
		memName1 = stMemberSymbolAccess.name.get( memChain );
		if( memName1 == NULL || memName1[0] == '\0'){
			continue;
		}
		astMemType = stMemberSymbolAccess.type.get( memChain );
		memNewChain = stLinkTypeInfoAccess.memChain.get( astNewType );

		while( memNewChain ){
			/*debug,13/1/10,S*/
			memName2 = stMemberSymbolAccess.name.get(memNewChain);
			if( memName2 != NULL && memName2[0] != '\0'){
				if( strcmp( memName1, memName2 )==0){
					astNewMemType = stMemberSymbolAccess.type.get(memNewChain);
					bRet = linkageCheckLinkType( astMemType, astNewMemType );
					if( bRet == FALSE ){
						return FALSE;
					}
					break;
				}
			}
			memNewChain = stMemberSymbolAccess.next.get( memNewChain );
			/*debug,13/1/10,E*/
		}
		if( memNewChain == 0 ){
			return FALSE;
		}
		/*debug,13/1/10,S*/
		memChain = stMemberSymbolAccess.next.get(memChain);
		/*debug,13/1/10,E*/
	}
	return TRUE;
}
static BOOL linkageCheckEnumLinkType( AST astType, AST astNewType ){
	AST memChain = stLinkTypeInfoAccess.memChain.get( astType );
	AST memNewChain = stLinkTypeInfoAccess.memChain.get( astNewType );
	U4  memNumber1=0;
	U4  memNumber2=0;
	AST astMemValue;
	AST astNewMemValue;
	PSZ memName1;
	PSZ memName2;

	if( astType == astNewType ){
		return TRUE;
	}
	memName1 = stLinkTypeInfoAccess.tagName.get( astType );
	memName2 = stLinkTypeInfoAccess.tagName.get( astNewType );
	if( memName1 != NULL && memName1[0] != '\0'){
		if( memName2 != NULL && memName2[0] != '\0'){
			if( strcmp( memName1, memName2 )){
				return FALSE;
			}
		}
	}

	memChain = stLinkTypeInfoAccess.memChain.get( astType );
	memNewChain = stLinkTypeInfoAccess.memChain.get( astNewType );
	while( memChain ){
		memNumber1++;
		memChain = stMemberSymbolAccess.next.get( memChain );
	}
	while( memNewChain ){
		memNumber2++;
		memNewChain = stMemberSymbolAccess.next.get( memNewChain );
	}
	if( memNumber1 != memNumber2 ){
		return FALSE;
	}
	memChain = stLinkTypeInfoAccess.memChain.get( astType );
	while(memChain){
		memName1 = stMemberSymbolAccess.name.get( memChain );
		memNewChain = stLinkTypeInfoAccess.memChain.get( astNewType );
		astMemValue = stMemberSymbolAccess.value.get( memChain );
		while( memNewChain ){
			if( strcmp( memName1, memName2 )==0){
				astNewMemValue = stMemberSymbolAccess.value.get( memNewChain );
				if( astMemValue == astNewMemValue ){
					break;
				}
			}
			memName2 = stMemberSymbolAccess.name.get( memNewChain );
		}
		if( memNewChain == 0 ){
			return FALSE;
		}
	}
	return TRUE;
}
static BOOL linkageCheckFunctionLinkType( AST astType, AST astNewType ){
	BOOL bRet;
	AST memChain;
	AST memNewChain;
	AST astMemType;
	AST astNewMemType;
	AST astOrgType;
	AST astNewOrgType;

	if( astType == astNewType ){
		return TRUE;
	}
	astOrgType = stLinkTypeInfoAccess.elementType.get( astType );
	astNewOrgType = stLinkTypeInfoAccess.elementType.get( astNewType );
	bRet = linkageCheckLinkType( astOrgType, astNewOrgType );
	if( bRet == FALSE ){
		return FALSE;
	}
	memChain = stLinkTypeInfoAccess.memChain.get( astType );
	memNewChain = stLinkTypeInfoAccess.memChain.get( astNewType );
	while( memChain ){
		if( memNewChain == 0 ){
			break;
		}
		astMemType = stMemberSymbolAccess.type.get( memChain );
		astNewMemType = stMemberSymbolAccess.type.get( memNewChain );

		bRet = linkageCheckLinkType( astMemType, astNewMemType );
		if( bRet == FALSE ){
			return FALSE;
		}
		memChain = stMemberSymbolAccess.next.get( memChain );
		memNewChain = stMemberSymbolAccess.next.get( memNewChain );
	}
	if( memChain != 0 || memNewChain != 0 ){
		return FALSE;
	}
	return TRUE;
}
static BOOL linkageCheckBitFieldLinkType( AST astType, AST astNewType ){
	return astType == astNewType;
}
static BOOL linkageCheckLinkType( AST astType, AST astNewType ){

	switch( stLinkTypeInfoAccess.typeKind.get( astType ) ){
		case TYPEKIND_BASIC			:	/* 通常の型			*/
			return linkageCheckBasicLinkType( astType, astNewType );
		case TYPEKIND_ARRAY			:	/* 配列				*/
			return linkageCheckArrayLinkType( astType, astNewType );
		case TYPEKIND_POINTER		:	/* ﾎﾟｲﾝﾀ			*/
			return linkageCheckPointerLinkType( astType, astNewType );
		case TYPEKIND_STRUCT		:	/* 構造体			*/
			return linkageCheckStructLinkType( astType, astNewType );
		case TYPEKIND_UNION			:	/* 共用体			*/
			return linkageCheckUnionLinkType( astType, astNewType );
		case TYPEKIND_ENUM			:	/* 列挙型			*/
			return linkageCheckEnumLinkType( astType, astNewType );
		case TYPEKIND_FUNCTION		:	/* 関数(実体)			*/
			return linkageCheckFunctionLinkType( astType, astNewType );
		case TYPEKIND_BITFIELD		:	/* BitField型			*/
			return linkageCheckBitFieldLinkType( astType, astNewType );
	}
	return FALSE;
}

VOID LinkageCheckFunction( AST astFunction, AST astNewFunction ){
	BOOL bRet;
	AST astType = stFunctionStorageAccess.type.get( astFunction );
	AST astNewType = stFunctionStorageAccess.type.get( astNewFunction );

	bRet = linkageCheckLinkType( astType, astNewType );
	if( bRet == FALSE ){
		//TODO: warning
	}
}
VOID LinkageCheckVariable( AST astVariable, AST astNewVariable ){
	BOOL bRet;
	AST astType = stVariableStorageAccess.type.get( astVariable );
	AST astNewType = stVariableStorageAccess.type.get( astNewVariable );

	bRet = linkageCheckLinkType( astType, astNewType );
	if( bRet == FALSE ){
		//TODO: warning
	}
}
static AST linkGetVariableInfo( AST astVariStorage ){
	AST astNewVari=0;
	AST astTemp;
	if( astVariStorage > 0 ){
		if( !stVariableStorageAccess.bDelete.get( astVariStorage ) ){
			astNewVari = stVariableStorageAccess.connect.get( astVariStorage );
			if( astNewVari == 0 ){
				stVariableInfoAccess.alloc(1);
				astNewVari = stVariableInfoAccess.getMax();
				stVariableStorageAccess.connect.set( astVariStorage, astNewVari );
				stVariableInfoAccess.codeScp.set( astNewVari,
						stVariableStorageAccess.codeScp.get( astVariStorage ));
				astTemp = stVariableStorageAccess.linkage.get( astVariStorage );
				if( astTemp > 0 ){
					astTemp = stCCLinkageStackAccess.vari.get( astTemp );
					stVariableInfoAccess.linkage.set( astNewVari, astTemp );
				}
				stVariableInfoAccess.name.set( astNewVari,
						stVariableStorageAccess.name.get( astVariStorage ));
				stVariableInfoAccess.symClass.set( astNewVari,
						stVariableStorageAccess.symClass.get( astVariStorage ));
				stVariableInfoAccess.type.set( astNewVari,
						stVariableStorageAccess.type.get( astVariStorage ));
				stVariableInfoAccess.bSizeVariable.set( astNewVari,
						stVariableStorageAccess.bSizeVariable.get( astVariStorage ));
				stVariableInfoAccess.child.set( astNewVari,
						linkGetVariableInfo( stVariableStorageAccess.child.get( astVariStorage ) ));
				stVariableInfoAccess.dataSection.set( astNewVari,
						stVariableStorageAccess.dataSection.get( astVariStorage ) );
				stVariableInfoAccess.initialCmdBegin.set( astNewVari,
						stVariableStorageAccess.initialCmdBegin.get( astVariStorage ) );
				stVariableInfoAccess.initialCmdEnd.set( astNewVari,
						stVariableStorageAccess.initialCmdEnd.get( astVariStorage ) );
				stVariableInfoAccess.length.set( astNewVari,
						stVariableStorageAccess.length.get( astVariStorage ) );
				stVariableInfoAccess.next.set( astNewVari,
						linkGetVariableInfo( stVariableStorageAccess.next.get( astVariStorage ) ));
				stVariableInfoAccess.offset.set( astNewVari,
						stVariableStorageAccess.offset.get( astVariStorage ));
				stVariableInfoAccess.parent.set( astNewVari,
						linkGetVariableInfo(stVariableStorageAccess.parent.get( astVariStorage )));
				stVariableInfoAccess.prev.set( astNewVari,
						linkGetVariableInfo(stVariableStorageAccess.prev.get( astVariStorage )));
				stVariableInfoAccess.value.set( astNewVari,
						stVariableStorageAccess.value.get( astVariStorage ));
			}
		}
	}
	return astNewVari;
}
static AST linkGetFunctionInfo( AST astFuncStorage ){
	AST astNewFunction=0;
	AST astTemp;
	/*debug,12/10/10,S*/
	AST astMaxCmdList = stCmdListAccess.getMax();
	AST astCmdIdx = 0;
	/*debug,12/10/10,E*/
	if( astFuncStorage > 0 ){
		if( !stFunctionStorageAccess.bDelete.get( astFuncStorage ) ){
			astNewFunction = stFunctionStorageAccess.connect.get( astFuncStorage );
			if( astNewFunction == 0 ){
				stFunctionInfoAccess.alloc(1);
				astNewFunction = stFunctionInfoAccess.getMax();
				stFunctionStorageAccess.connect.set( astFuncStorage, astNewFunction );
				stFunctionInfoAccess.codeScp.set( astNewFunction,
						stFunctionStorageAccess.codeScp.get( astFuncStorage ));
				stFunctionInfoAccess.functionEntry.set( astNewFunction,
						stFunctionStorageAccess.functionEntry.get( astFuncStorage ));
				stFunctionInfoAccess.functionExit.set( astNewFunction,
							stFunctionStorageAccess.functionExit.get( astFuncStorage ));
				astTemp = stFunctionStorageAccess.linkage.get( astFuncStorage );
				if( astTemp > 0 ){
					astTemp = stCCLinkageStackAccess.vari.get( astTemp );
					stFunctionInfoAccess.linkage.set( astNewFunction, astTemp );
				}
				stFunctionInfoAccess.name.set( astNewFunction,
							stFunctionStorageAccess.name.get( astFuncStorage ));
				stFunctionInfoAccess.symClass.set( astNewFunction,
							stFunctionStorageAccess.symClass.get( astFuncStorage ));
				stFunctionInfoAccess.type.set( astNewFunction,
							stFunctionStorageAccess.type.get( astFuncStorage ));
				/*debug,12/10/10,S*/
				stFunctionInfoAccess.storeID.set(astNewFunction,astFuncStorage);
				if(astNewFunction != astFuncStorage){
					for(astCmdIdx = MIN_ARRAY; astCmdIdx <= astMaxCmdList; astCmdIdx++){
						if(!stCmdListAccess.bChg.get(astCmdIdx)){
							if(astFuncStorage == stCmdListAccess.function.get(astCmdIdx)){
								stCmdListAccess.function.set(astCmdIdx,astNewFunction);
								stCmdListAccess.bChg.set(astCmdIdx,TRUE);
							}
						}
					}
				}
				/*debug,12/10/10,E*/
			}
		}
	}
	return astNewFunction;
}
S4 DLL_EXPORT LinkageSetting( VOID ){
	AST astCCLinkage=0;
	PSZ name;
	AST astCCMaxLinkage = 0;
	AST astTempLinkage;
	AST astVari;
	AST astNewVari;

	BOOL bRet;
	astCCMaxLinkage = stCCLinkageStackAccess.getMax();
	for( astCCLinkage = MIN_ARRAY; astCCLinkage <= astCCMaxLinkage; astCCLinkage++ ){
		if( stCCLinkageStackAccess.decVari.get( astCCLinkage )==0 ){
			continue;
		}
		if( stCCLinkageStackAccess.bExternal.get( astCCLinkage )){
			astNewVari = stCCLinkageStackAccess.decVari.get( astCCLinkage );
			bRet = FALSE;
			if( stCCLinkageStackAccess.bFunction.get( astCCLinkage )){
				bRet = TRUE;
			}
			if( bRet ){
				name = stFunctionStorageAccess.name.get( astNewVari );
			}else{
				name = stVariableStorageAccess.name.get( astNewVari );
			}
			astTempLinkage = stTempLinkageAccess.addLinkage(name);
			stTempLinkageAccess.bExternal.set( astTempLinkage, TRUE );
			astVari = stTempLinkageAccess.vari.get( astTempLinkage );
			if( astVari == 0 ){
				astVari = stTempLinkageAccess.tenVari.get( astTempLinkage );
				if( astVari == 0 ){
					astVari = stTempLinkageAccess.decVari.get( astTempLinkage );
				}
			}

			if( astVari != 0 && astNewVari != 0 && astVari != astNewVari ){
				if( bRet ){
					if( !stTempLinkageAccess.bFunction.get( astTempLinkage ) ){
						//TODO: different types
					}else{
						LinkageCheckFunction( astVari, astNewVari );
						stTempLinkageAccess.bFunction.set( astTempLinkage, TRUE );
					}
				}else{
					if( stTempLinkageAccess.bFunction.get( astTempLinkage ) ){
						//TODO: different types
					}else{
						LinkageCheckVariable( astVari, astNewVari );
					}
				}
			}
			if( stCCLinkageStackAccess.bFunction.get( astCCLinkage )){
				stTempLinkageAccess.bFunction.set( astTempLinkage, TRUE );
			}
			if( stTempLinkageAccess.vari.get( astTempLinkage )
				&& stCCLinkageStackAccess.vari.get( astCCLinkage )){
				//TODO: duplicate definitions
			}
		}else{
			stTempLinkageAccess.alloc(1);
			astTempLinkage = stTempLinkageAccess.getMax();
			astNewVari = stCCLinkageStackAccess.vari.get( astCCLinkage );
			if( astNewVari == 0 ){
				astNewVari = stCCLinkageStackAccess.tenVari.get( astCCLinkage );
				if( astNewVari == 0 ){
					astNewVari = stCCLinkageStackAccess.decVari.get( astCCLinkage );
				}
			}
			bRet = FALSE;
			if( stCCLinkageStackAccess.bFunction.get( astCCLinkage )){
				bRet = TRUE;
				/*debug,12/10/09,S*/
				stTempLinkageAccess.bFunction.set( astTempLinkage, TRUE );
				/*debug,12/10/09,E*/
			}
			if( bRet ){
				name = stFunctionStorageAccess.name.get( astNewVari );
			}else{
				name = stVariableStorageAccess.name.get( astNewVari );
			}
			astVari = stTempLinkageAccess.vari.get( astTempLinkage );
			if( astVari == 0 ){
				astVari = stTempLinkageAccess.tenVari.get( astTempLinkage );
				if( astVari == 0 ){
					astVari = stTempLinkageAccess.decVari.get( astTempLinkage );
				}
			}
		}
		if( stCCLinkageStackAccess.refer.get( astCCLinkage )){
			stTempLinkageAccess.refer.set( astTempLinkage, TRUE );
		}
		if( stTempLinkageAccess.vari.get( astTempLinkage ) ){
			if( bRet ){
				stFunctionStorageAccess.bDelete.set( astNewVari, TRUE );
			}else{
				stVariableStorageAccess.bDelete.set( astNewVari, TRUE );
			}

		}else if( stCCLinkageStackAccess.vari.get( astCCLinkage ) ){
			if( bRet ){
				stFunctionStorageAccess.bDelete.set( astVari, TRUE );
			}else{
				stVariableStorageAccess.bDelete.set( astVari, TRUE );
			}
			stTempLinkageAccess.vari.set( astTempLinkage, astNewVari );
			stTempLinkageAccess.decVari.set( astTempLinkage, astNewVari );
		}else if( stTempLinkageAccess.tenVari.get( astTempLinkage ) ){
			if( bRet ){
				stFunctionStorageAccess.bDelete.set( astNewVari, TRUE );
			}else{
				stVariableStorageAccess.bDelete.set( astNewVari, TRUE );
			}
		}else if( stCCLinkageStackAccess.tenVari.get( astCCLinkage ) ){
			if( bRet ){
				stFunctionStorageAccess.bDelete.set( astVari, TRUE );
			}else{
				stVariableStorageAccess.bDelete.set( astVari, TRUE );
			}
			stTempLinkageAccess.tenVari.set( astTempLinkage, astNewVari );
		}else if( stTempLinkageAccess.decVari.get( astTempLinkage ) ){
			if( bRet ){
				stFunctionStorageAccess.bDelete.set( astNewVari, TRUE );
			}else{
				stVariableStorageAccess.bDelete.set( astNewVari, TRUE );
			}
			stVariableStorageAccess.bDelete.set( astNewVari, TRUE );
		}else if( stCCLinkageStackAccess.decVari.get( astCCLinkage ) ){
			stTempLinkageAccess.decVari.set( astTempLinkage, astNewVari );
		}
		if( stCCLinkageStackAccess.vari.get( astCCLinkage ) ){
			stTempLinkageAccess.vari.set( astTempLinkage, astNewVari );
		}
		if( stCCLinkageStackAccess.tenVari.get( astCCLinkage )){
			stTempLinkageAccess.tenVari.set( astTempLinkage, astNewVari );
		}
		stTempLinkageAccess.decVari.set( astTempLinkage, astNewVari );
		stCCLinkageStackAccess.vari.set( astCCLinkage, astTempLinkage );

	}
	astCCMaxLinkage = stTempLinkageAccess.getMax();
	for( astCCLinkage = MIN_ARRAY; astCCLinkage <= astCCMaxLinkage; astCCLinkage++ ){
		stGblLinkageAccess.alloc(1);
		stGblLinkageAccess.bExternal.set( astCCLinkage, stTempLinkageAccess.bExternal.get( astCCLinkage ) );
		stGblLinkageAccess.refer.set( astCCLinkage, stTempLinkageAccess.refer.get( astCCLinkage ) );
		astVari = stTempLinkageAccess.vari.get( astCCLinkage );
		if( astVari == 0 ){
			astVari = stTempLinkageAccess.tenVari.get( astCCLinkage );
			if( astVari == 0 ){
				//TODO:warning no definition
				astVari = stTempLinkageAccess.decVari.get( astCCLinkage );
			}
		}
		if( stTempLinkageAccess.bFunction.get( astCCLinkage ) ){
			astVari = linkGetFunctionInfo( astVari );
			stGblLinkageAccess.bFunction.set( astCCLinkage, TRUE );
		}else{
			astVari = linkGetVariableInfo( astVari );
			stGblLinkageAccess.bFunction.set( astCCLinkage, FALSE );
		}
		stGblLinkageAccess.vari.set( astCCLinkage, astVari );
	}
	astCCMaxLinkage = stVariableStorageAccess.getMax();
	for( astVari = MIN_ARRAY; astVari <= astCCMaxLinkage; astVari++  ){
		if( stVariableStorageAccess.parent.get( astVari ) == 0 ){
			if( stVariableStorageAccess.connect.get( astVari ) == 0 ){
				if( stVariableStorageAccess.bDelete.get( astVari ) == FALSE ){
					linkGetVariableInfo( astVari );
				}
			}
		}
	}
	astCCMaxLinkage = stFunctionStorageAccess.getMax();
	for( astVari = MIN_ARRAY; astVari <= astCCMaxLinkage; astVari++  ){
		if( stFunctionStorageAccess.connect.get( astVari ) == 0 ){
			if( stFunctionStorageAccess.bDelete.get( astVari ) == FALSE ){
				linkGetFunctionInfo( astVari );
			}
		}
	}
	astCCMaxLinkage = stOperandAccess.getMax();
	for( astVari = MIN_ARRAY; astVari <= astCCMaxLinkage; astVari++  ){
		if( stOperandAccess.kind.get( astVari ) == OPERAND_OBJECT ){
			astNewVari = linkGetVariableInfo( stOperandAccess.parameter.get( astVari ) );
			if( astNewVari == 0 ){
				astNewVari = stOperandAccess.parameter.get( astVari );
				if( astNewVari != 0 ){
					astNewVari = stVariableStorageAccess.linkage.get( astNewVari );
					if( astNewVari != 0 ){
						astNewVari = stCCLinkageStackAccess.vari.get( astNewVari );
						astNewVari = stGblLinkageAccess.vari.get( astNewVari );
					}
				}
			}
			stOperandAccess.parameter.set( astVari, astNewVari);
		}else if( stOperandAccess.kind.get( astVari ) == OPERAND_FUNCTION ){
			astNewVari = linkGetFunctionInfo( stOperandAccess.parameter.get( astVari ) );
			if( astNewVari == 0 ){
				astNewVari = stOperandAccess.parameter.get( astVari );
				if( astNewVari != 0 ){
					astNewVari = stFunctionStorageAccess.linkage.get( astNewVari );
					if( astNewVari != 0 ){
						astNewVari = stCCLinkageStackAccess.vari.get( astNewVari );
						astNewVari = stGblLinkageAccess.vari.get( astNewVari );
					}
				}
			}
			stOperandAccess.parameter.set( astVari, astNewVari);
		}
	}
//	printAllCmdList();
//	printAllVariable();
	return COEXIT_SUCCESS;
}

